package com.ctgu.programme;


public class Prime {
    public static void main(String[] args) {
        int cnt = 0,maxn = 20001;
        int[] b = new int[maxn];//0为素数，1不是素数
        int[] p = new int[maxn];//保存素数
        for (int i = 2; i < maxn; i++) {
            if(b[i] == 0){
                p[cnt++] = i;
            }
            for(int j = 0; p[j]*i < maxn && j < cnt; j++){
                b[p[j]*i] = 1;
                if(i % p[j] == 0){
                    break;
                }
            }
        }
        for (int i = 0; i < cnt; i++) {
            System.out.print(p[i] + " ");
            if((i + 1) % 5 == 0)
                System.out.println();
        }
    }
}
